package com.lening.DuanXin;


import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

/**
 * @author 李文军
 * @author 你我山巅自相逢
 * @version 1.0
 * @date 2021/3/31 8:56
 */
public class FaSong {
    public static void main(String[] args)throws Exception{

        HttpClient client = new HttpClient();
        //中国网建的网站路径 6
        PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");
        post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
        NameValuePair[] data ={
                new NameValuePair("Uid", "li18402102735"),//注册的账号
                new NameValuePair("Key", "d41d8cd98f00b204e980"),//短信秘钥
                new NameValuePair("smsMob","18402102735"),//接收方的电话号码
                new NameValuePair("smsText","Java测试短信验证您的验证码为:521521,请尽快输入，有效期5分钟")//短信内容
        };
        post.setRequestBody(data);

        client.executeMethod(post);
        Header[] headers = post.getResponseHeaders();
        int statusCode = post.getStatusCode();
        System.out.println("statusCode:"+statusCode);

        for(Header h : headers){
            System.out.println(h.toString());
        }
        String result = new String(post.getResponseBodyAsString().getBytes("gbk"));
        System.out.println(result);

        post.releaseConnection();
    }

}
